<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script src="js/jquery-1.11.3.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			 function checkName(){
				var input1 = document.getElementById("spanId");
				var nameInput = document.getElementById("nameId").value;
				var reg =/\w{5,11}/;
				if (reg.test(nameInput)) {
					input1.className = "ok";
				}else{
					input1.className = "error";
					return;
				}
				$.post(
					"/JavaWeb1907/student?method=checkName",
					{"nameInput":nameInput},
					function(jsonObj){
						if(jsonObj.isExist){
							$("#nameExistId").html("该用户已存在");
						}else{
							$("#nameExistId").html("该名字可以使用");
						}
					},
					"json"
				);
			}
		    function checkEmail(){
				var input1 = document.getElementById("spanId2");
				var EmailInput = document.getElementById("EmailId").value;
				var reg =/^\d{5,11}(@\w{2,5}\.com)$/;
				if (reg.test(EmailInput)) {
					input1.className = "ok";
				}else{
					input1.className = "error";
				}
			}
		</script>
		<style type="text/css">
			.ok{
				color: green;
			}
			.error{
				color: red;
			}
		</style>
	</head>
	<body>
		用户名：<input type="text" id="nameId" onblur="checkName()"/>
		<span id="spanId">5-10位字母、数字、下划线</span>
		<span id="nameExistId"></span>
		<br />
		Email：<input type="text" id="EmailId" onblur="checkEmail()" /><span id="spanId2">必须符合邮箱的格式</span>
	</body>
</html>
